var nt = nt || {};
var ntParameter = getParameter();
var ntFunctionSrc = nt.script || ntParameter.script;
var ntSiteID = nt.siteid || ntParameter.siteid;
var ntUID = nt.uid || ntParameter.uid;
var ntUName = nt.uname || ntParameter.uname;
var ntSessionID = nt.sid || ntParameter.sid;
var ntUserParam = nt.param || "";
var ntCustomParams = nt.customParam || "";

var supAsyLoad = true,doc = document,ua = window.navigator.userAgent.toLowerCase(); 
(function(callback) {
	var elem,args = arguments,done = false,async = getAsync();
	if (/msie/.test(ua) && !/opera/.test(ua)) {
		if (!doc.body) {
			return setTimeout(function() {
				args.callee.apply(this, args)
			}, 100);
		}
	} else if (!async) {
		if (supAsyLoad) {
			supAsyLoad = false;
			return setTimeout(function() {
				args.callee.apply(this, args)
			}, 100);
		}
	}
	elem = doc.createElement('script');
	elem.setAttribute('id', 'ntalkerimfunction');
	elem.setAttribute('language', 'javascript');
	elem.setAttribute('type', 'text/javascript');
	elem.setAttribute('charset', 'utf-8');
	async && elem.setAttribute('async', true);
	elem.setAttribute('src', ntFunctionSrc);
	elem.onload = elem.onreadystatechange = function() {
		if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
			done = true;
			elem.onreadystatechange = null;
			callback();
		}
	};
	var head = document.getElementsByTagName("head")[0] || document.documentElement;
	head.insertBefore(elem, head.firstChild);
})(function(){
	if (typeof im_connectIM == 'undefined') {
		//throw 'ntalker script Load failure.';
	} else {
		im_connectIM(ntSiteID, ntUID, ntUName, ntSessionID, ntUserParam, ntCustomParams);
		
		if(typeof im_showSiteMessage != 'undefined' && siteMsgInfoArray){
			im_showSiteMessage(siteMsgInfoArray);
		}
		if(typeof im_myMenu != 'undefined' && tbMenuMyApp){
			im_myMenu(tbMenuMyApp);
		}
	}
});

function getAsync(){
	try{
		var elem = document.createElement('script'),async = typeof(elem.async) != "undefined";
		elem.removeChild(elem);
	}catch(e){}
	return async;
}
function getParameter() {
	var scripts = document.getElementsByTagName("script"),
	script = scripts[(scripts.length - 1)],
	src = script.src,
	reg = /(?:\?|&)(.*?)=(.*?)(?=&|$)/g,
	temp,
	res = {};
	while ((temp = reg.exec(src)) != null) {
		res[temp[1]] = decodeURIComponent(temp[2]);
	}
	return res;
}
